package  com.ahntanya;

import android.os.Bundle;
import android.app.Activity;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ImageSwitcher;
import android.widget.ImageView;
import android.widget.ViewSwitcher;


public class MainActivity extends Activity implements View.OnClickListener, ViewSwitcher.ViewFactory {

	int [] images = {R.drawable.pic1, R.drawable.pic2, R.drawable.pic3, 
					 R.drawable.pic4, R.drawable.pic5, R.drawable.pic6,
					 R.drawable.pic7, R.drawable.pic8, R.drawable.pic9};
	int imageCnt = 0;
	
	Button button;
	ImageSwitcher switcher;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		switcher = (ImageSwitcher) findViewById(R.id.imageSwitcher);
		switcher.setFactory(this);
		switcher.setInAnimation(AnimationUtils.loadAnimation(this, android.R.anim.fade_in));
		switcher.setOutAnimation(AnimationUtils.loadAnimation(this, android.R.anim.fade_out));
		
		button = (Button) findViewById(R.id.button);
		button.setOnClickListener(this);
	}
		
	@Override
	public void onClick(View v) {
		switcher.setImageResource(images[imageCnt++]);
		
		if(imageCnt > images.length-1) {
			imageCnt = 0;
		}
	}
	
	@Override
	public View makeView() {
		ImageView imageView = new ImageView(this);
		imageView.setScaleType(ImageView.ScaleType.FIT_CENTER);
		imageView.setLayoutParams(new ImageSwitcher.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
		imageView.setBackgroundColor(0xFF000000);
		
		return imageView;
	}
}
